<?php include "../../config.php";?>
<?php include ROOT_PATH_."/front/m2/coresection/checkUserSession.php";?>

<?$userinfo = select_one_line_all_items($table_Prefix."user","mid = '".$user_mid."'"); ?>
<?$site     = select_one_line_all_items($table_Prefix."site","nid !='-1' ");;?>

<? if($_REQUEST['date'])
{
    if($_REQUEST['date']<=date("Y-m-d")){$_REQUEST['date']=date("Y-m-d",strtotime("+1 day"));}
        $menu_str="applydate = '".$_REQUEST['date']."'";}
else{
//要判断是否显示今日的菜式
    if(date("Hi")<"1730")
    {$menu_start_date=date("Y-m-d",strtotime("+1 day"));}
    else
    {
     $menu_start_date=date("Y-m-d",strtotime("+2 day"));
    }

        $menu_str="applydate >= '".$menu_start_date."'";}
?>
<?$menu     = select_lines_all_items   ($tabel_prefix."menu","applydate asc,at asc",$menu_str,"")?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <?php include 'modules/head.php'; ?>

</head>

<body>

<div class="topbar"><?php include 'modules/topbar.php'; ?></div>



<!--menu start-->
<div class="sidebar"><?php include 'modules/sidebar.php'; ?></div>
<!--menu end-->



<div class="container">




<div  id="content" class="content dishes_list">


<h2><?if(!$_REQUEST['date']){echo "全部菜式";}else{echo $_REQUEST['date'];}?></h2>

<?
for($i=0;$i<count($menu);$i++){
if($menu[$i]['at']=='1'){$meal='早餐';}
if($menu[$i]['at']=='2'){$meal='午餐';}
if($menu[$i]['at']=='3'){$meal='晚餐';}
?>



<form id="orderlist"  method="post" action="coresection/submit_order.php">

    <div class="box">
        <input type="hidden" name="ai_product_name[]" value="<?echo $menu[$i]['name']?>">
        <input type="hidden" name="ai_product_id[]" value="<?echo $menu[$i]['product_id']?>">
        <input type="hidden" name="ai_product_price[]" value="<?echo $menu[$i]['price']?>">
        <input type="hidden" name="ai_order_date[]" value="<?echo $menu[$i]['applydate']?>">
        <input type="hidden" name="ai_order_at[]" value="<?echo $menu[$i]['at']?>">


        <img src="/front/m2/images/zaocan.jpg">
        <h6><?echo $menu[$i]['name']?></h6>
        <div class="content"><?echo substr($menu[$i]['applydate'],5,5)?> / <?echo $meal?></div>
        <div class="data">￥<span id="price"><?echo $menu[$i]['price']?></span></div>
        <div class="shuliang">

<div class="jiancan"
     onclick="jiancan('<?echo $menu[$i]['product_id']?>','<?echo $menu[$i]['price']?>')">
</div>

<input type="text" value="0" name="ai_product_num[]" id="<?echo $menu[$i]['product_id']?>" readonly="readonly " >

<div class="jiacan"
     onclick="jiacan('<?echo $menu[$i]['product_id']?>','<?echo $menu[$i]['price']?>')">
</div>


</div>

    </div>

<?
    }?>


</form>


</div>





</div>





<div class="dishesfooter">
    <div id="gouwuche">
        <div class="gouwuche_shuliang">0</div>
    </div>
    <p>￥<span id="tatalprices">0</span></p>
    <div id="order_button" class="footer_button">结算</div>
</div>




<div class="footer"><?php include 'modules/footer.php'; ?></div>


</body>
</html>


<script>

    function consume_num(num){   //计算总共点餐的数量，并显示在左下角的购物车上

        nownum_txt=$("#gouwuche .gouwuche_shuliang").html();
        nownum=(parseInt(nownum_txt)+num);
        $("#gouwuche .gouwuche_shuliang").html(nownum);



    }





    function consume_price(price){  //计算总价钱



        price_txt=$("#tatalprices").html();

        nowprice=(parseFloat(price_txt)+parseFloat(price));

        newprice=nowprice.toFixed(1).toString();
        $("#tatalprices").html(nowprice);
    }




    function jiacan(id,price){ //加一分餐

       var numval = $("#"+id).val();


        if(numval>=0 && numval<=10)//判断不能超过这个范围的数
        {

          $("#"+id).val(parseInt(numval) + 1);
            consume_num(+1);
            consume_price(price);
        }



 }



    function jiancan(id,price){//减一分餐


        var numval = $("#"+id).val();


        if(numval>0 && numval<=11)//判断不能超过这个范围的数
        {

            $("#"+id).val(parseInt(numval) - 1);
            consume_num(-1);

            newprice=-1*price

            consume_price(newprice);
        }



    }








//提交订单
    $("#order_button").click(function(){
        var form = document.getElementById('orderlist');
        form.submit();
    });





    $(".sidebar li").click(function(){
        var dishisday = $(this).children("span").html().substring(0,11);

        if($("#tatalprices").html() == 0){  //如果没有选中的餐，则可以随意更改日期
            $(".dishe_list .dishestitle span").html(dishisday);
            $(".sidebar li").removeClass("active");
            $(this).addClass("active");
            return;
        }
        if($(this).hasClass("active") == false){
            var con = confirm("点击确认后更换日期重新选择餐点");
            if (con == true) {
                $(".dishes_list .dishestitle span").html(dishisday);
                $(".sidebar li").removeClass("active");
                $(this).addClass("active");


                //清空点餐
                $("#dishes1").val(0);
                $("#dishes2").val(0);
                $("#dishes3").val(0);
                consume_num();

            }
        }

    });


</script>